home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / turbovis / tvtool17.zip / CALCUL.H < prev    next >
C/C++ Source or Header  |  1993-03-02  |  3KB  |  114 lines

  1. /*-------------------------------------------------------*/
  2. /*                                                       */
  3. /*   Calc.h: Header file for Calc.cpp                    */
  4. /*-------------------------------------------------------*/
  5.  
  6. #if ! defined( __CALCUL_H ) && defined(Uses_TCalculator)
  7. #define __CALCUL_H
  8.  
  9. #if !defined( __MATH_H )
  10. #include <math.h>
  11. #endif       // __MATH_H
  12.  
  13.  
  14. class TEvent;
  15. class TPalette;  
  16.             
  17. #define DISPLAYLEN  25      // Length (width) of calculator display
  18.  
  19. enum TCalcState { csFirst = 1, csValid, csError };
  20.  
  21. const int cmCalcButton  = 200;
  22.  
  23.  
  24. class TCalcDisplay : public TView
  25. {
  26.  
  27. public:
  28.  
  29.     TCalcDisplay(TRect& r);
  30.     TCalcDisplay( StreamableInit ) : TView(streamableInit) { };
  31.     ~TCalcDisplay();
  32.     virtual TPalette& getPalette() const;
  33.     virtual void handleEvent(TEvent& event);
  34.     virtual void draw();
  35.  
  36. private:
  37.  
  38.     TCalcState status;
  39.     char *number;
  40.     char sign;
  41.     char operate;           // since 'operator' is a reserved word.
  42.     double operand;
  43.  
  44.     void calcKey(unsigned char key);
  45.     void checkFirst();
  46.     void setDisplay(double r);
  47.     void clear();
  48.     void error();
  49.     inline double getDisplay() { return( atof( number ) ); };
  50.  
  51.     virtual const char *streamableName() const
  52.         { return name; }
  53.  
  54. protected:
  55.  
  56.     virtual void write( opstream& );
  57.     virtual void *read( ipstream& );
  58.  
  59. public:
  60.  
  61.     static const char * const name;
  62.     static TStreamable *build();
  63.  
  64. };
  65.  
  66. inline ipstream& operator >> ( ipstream& is, TCalcDisplay& cl )
  67.     { return is >> (TStreamable&) cl; }
  68. inline ipstream& operator >> ( ipstream& is, TCalcDisplay*& cl )
  69.     { return is >> (void *&) cl; }
  70.  
  71. inline opstream& operator << ( opstream& os, TCalcDisplay& cl )
  72.     { return os << (TStreamable&) cl; }
  73. inline opstream& operator << ( opstream& os, TCalcDisplay* cl )
  74.     { return os << (TStreamable *) cl; }
  75.  
  76.  
  77. class TCalculator : public TDialog
  78. {
  79.  
  80. public:
  81.  
  82.     TCalculator();
  83.     TCalculator( StreamableInit ) :
  84.         TDialog(streamableInit), TWindowInit(&TCalculator::initFrame) { };
  85.  
  86. private:
  87.  
  88.     virtual const char *streamableName() const
  89.         { return name; }
  90.  
  91. //protected:
  92.  
  93. //    virtual void write( opstream& );
  94. //    virtual void *read( ipstream& );
  95.  
  96. public:
  97.  
  98.     static const char * const name;
  99.     static TStreamable *build();
  100.  
  101. };
  102.  
  103. inline ipstream& operator >> ( ipstream& is, TCalculator& cl )
  104.     { return is >> (TStreamable&) cl; }
  105. inline ipstream& operator >> ( ipstream& is, TCalculator*& cl )
  106.     { return is >> (void *&) cl; }
  107.  
  108. inline opstream& operator << ( opstream& os, TCalculator& cl )
  109.     { return os << (TStreamable&) cl; }
  110. inline opstream& operator << ( opstream& os, TCalculator* cl )
  111.     { return os << (TStreamable *) cl; }
  112.  
  113. #endif      // __CALC_H
  114.